import request from "@/utils/http";

// 分页查询商品
export function queryItemByPageAPI(query, truth) {
    return request({
        url: '/items/page',
        method: 'get',
        params: {
            ...query,
            truth // 可选的请求头参数
        }
    });
}


export function listItemByBusinessIdAPI(business_id) {
    return request({
        url: '/items/byBusinessId',
        method: 'get',
        params: {business_id}
    })
}


export function queryItemByCategoryAPI(category) {
    return request({
        url: '/items/byCategory',
        method: 'get',
        params: {
            category
        }
    });
}


// 根据id批量查询商品
export function queryItemByIdsAPI(ids) {
    return request({
        url: '/items/byIds',
        method: 'get',
        params: {
            ids
        }
    });
}

// 根据id查询商品
export function queryItemByIdAPI(id) {
    return request({
        url: `/items/${id}`,
        method: 'get'
    });
}

// 新增商品
export function saveItemAPI(item) {
    return request({
        url: '/items',
        method: 'post',
        data: item
    });
}

// 更新商品状态
export function updateItemStatusAPI(id, status) {
    return request({
        url: `/items/status/${id}/${status}`,
        method: 'put'
    });
}

// 更新商品
export function updateItemAPI(item) {
    return request({
        url: '/items',
        method: 'put',
        data: item
    });
}

// 根据id删除商品
export function deleteItemByIdAPI(id) {
    return request({
        url: `/items/${id}`,
        method: 'delete'
    });
}

// 批量扣减库存
export function deductStockAPI(items) {
    return request({
        url: '/items/stock/deduct',
        method: 'put',
        data: items
    });
}

// 搜索商品
export function searchItemsAPI(query) {
    return request({
        url: '/search/list',
        method: 'get',
        params: {
            key: query.key,
            brand: query.brand,
            category: query.category,
            minPrice: query.minPrice,
            maxPrice: query.maxPrice,
            page: query.page, // 假设这里的分页参数是一个对象，包含page和pageSize字段
            pageSize: query.pageSize
        }
    });
}
